﻿Imports System.Windows.Forms
Imports System.Drawing

Public Class ContainerPictureBox
    Inherits Panel

    Private WithEvents Button3D2 As New UCBase.Button3D
    Private Panel1 As New TransPanel
    Private Label1 As New System.Windows.Forms.Label
    Private Label2 As New System.Windows.Forms.Label
    Private Label3 As New System.Windows.Forms.Label
    Private Label4 As New System.Windows.Forms.Label
    Private Label5 As New System.Windows.Forms.Label
    Private Label6 As New System.Windows.Forms.Label
    Private M_OSD_Opacity As Integer = 50
    Private M_OSB_BackColor As System.Drawing.Color = Drawing.Color.Black
    Private M_OSD_TextColor As System.Drawing.Color = Drawing.Color.White

    Private M_Pic As bitmap
    Private PT As Integer
    Private AC As Integer = 0
    Private AV As Integer = 0
    Private FPS As Integer
    Public Sub New()

        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        Me.SetStyle(ControlStyles.UserPaint, True)
        Me.UpdateStyles()

        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        Me.BackColor = Drawing.Color.Black
        '
        'Panel1
        '

        Me.Panel1.BackColor = System.Drawing.Color.FromArgb(CType(CType(127, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer))
        Me.Panel1.Controls.Add(Me.Label6)
        Me.Panel1.Controls.Add(Me.Button3D2)
        Me.Panel1.Controls.Add(Me.Label5)
        Me.Panel1.Controls.Add(Me.Label4)
        Me.Panel1.Controls.Add(Me.Label1)
        Me.Panel1.Controls.Add(Me.Label3)
        Me.Panel1.Controls.Add(Me.Label2)
        Me.Panel1.Location = New System.Drawing.Point(0, -65)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(180, 100)
        Me.Panel1.TabIndex = 101
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.Color.White
        Me.Label1.Location = New System.Drawing.Point(5, 5)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(90, 20)
        Me.Label1.TabIndex = 101
        Me.Label1.Text = "Dimension : "
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.Color.White
        Me.Label2.Location = New System.Drawing.Point(5, 25)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(90, 20)
        Me.Label2.TabIndex = 102
        Me.Label2.Text = "Color Depth : "
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.Color.Transparent
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.ForeColor = System.Drawing.Color.White
        Me.Label3.Location = New System.Drawing.Point(5, 45)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(90, 20)
        Me.Label3.TabIndex = 103
        Me.Label3.Text = "FPS : "
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label4
        '
        Me.Label4.BackColor = System.Drawing.Color.Transparent
        Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.ForeColor = System.Drawing.Color.White
        Me.Label4.Location = New System.Drawing.Point(95, 5)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(80, 20)
        Me.Label4.TabIndex = 104
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label5
        '
        Me.Label5.BackColor = System.Drawing.Color.Transparent
        Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.ForeColor = System.Drawing.Color.White
        Me.Label5.Location = New System.Drawing.Point(95, 25)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(80, 20)
        Me.Label5.TabIndex = 105
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label6
        '
        Me.Label6.BackColor = System.Drawing.Color.Transparent
        Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label6.ForeColor = System.Drawing.Color.White
        Me.Label6.Location = New System.Drawing.Point(95, 45)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(80, 20)
        Me.Label6.TabIndex = 106
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Button3D2
        '
        Me.Button3D2.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.Button3D2.BackColor = System.Drawing.Color.Transparent
        Me.Button3D2.ButtonImage = Nothing
        Me.Button3D2.ButtonImageCustomResize = 75
        Me.Button3D2.ButtonImageMode = UCBase.Button3D.ButtonImageModeConst.None
        Me.Button3D2.ButtonImageOffsetX = 0
        Me.Button3D2.ButtonImageOffsetY = 0
        Me.Button3D2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Button3D2.ForeColor = System.Drawing.Color.DodgerBlue
        Me.Button3D2.HiLiteColor = System.Drawing.Color.Red
        Me.Button3D2.Location = New System.Drawing.Point(5, 70)
        Me.Button3D2.Name = "Button3D2"
        Me.Button3D2.Opacity = 100
        Me.Button3D2.Size = New System.Drawing.Size(170, 25)
        Me.Button3D2.TabIndex = 100
        Me.Button3D2.Text = "Hide"
        Me.Button3D2.TextColor = System.Drawing.Color.White
        Me.Button3D2.TextOffsetX = 0
        Me.Button3D2.TextOffsetY = 1
        '
        'UserControl1
        '
        Me.Controls.Add(Me.Panel1)
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub
    Private Sub UpdateControls()

        Me.Label1.ForeColor = M_OSD_TextColor
        Me.Label2.ForeColor = M_OSD_TextColor
        Me.Label3.ForeColor = M_OSD_TextColor
        Me.Label4.ForeColor = M_OSD_TextColor
        Me.Label5.ForeColor = M_OSD_TextColor
        Me.Label6.ForeColor = M_OSD_TextColor

        Me.Refresh()

    End Sub
    <System.ComponentModel.Category("OSD")> _
    <System.ComponentModel.Description("Background Opacity")> _
    <System.ComponentModel.DisplayName("Opacity")> _
    <System.ComponentModel.DefaultValue(50)> _
    Public Property OSDOpacity() As Integer
        Get
            Return M_OSD_Opacity
        End Get
        Set(ByVal value As Integer)
            If value > -1 And value < 101 Then
                M_OSD_Opacity = value
                Me.Panel1.BackColor = System.Drawing.Color.FromArgb((M_OSD_Opacity * 2.55), M_OSB_BackColor.R, M_OSB_BackColor.G, M_OSB_BackColor.B)
            End If
        End Set
    End Property
    <System.ComponentModel.Category("OSD")> _
    <System.ComponentModel.Description("Background Color")> _
    <System.ComponentModel.DisplayName("Background Color")> _
    Public Property OSDBack() As System.Drawing.Color
        Get
            Return M_OSB_BackColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            M_OSB_BackColor = value
            Me.Panel1.BackColor = System.Drawing.Color.FromArgb((M_OSD_Opacity * 2.55), M_OSB_BackColor.R, M_OSB_BackColor.G, M_OSB_BackColor.B)
        End Set
    End Property
    <System.ComponentModel.Category("OSD")> _
    <System.ComponentModel.Description("Text Color")> _
    <System.ComponentModel.DisplayName("Text Color")> _
    Public Property OSDFore() As System.Drawing.Color
        Get
            Return M_OSD_TextColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            M_OSD_TextColor = value
            UpdateControls()
        End Set
    End Property
    <System.ComponentModel.Category("OSD")> _
    <System.ComponentModel.Description("Button Color")> _
    <System.ComponentModel.DisplayName("Button Color")> _
    Public Property ButtonFore() As System.Drawing.Color
        Get
            Return Me.Button3D2.ForeColor

        End Get
        Set(ByVal value As System.Drawing.Color)
            Me.Button3D2.ForeColor = value
        End Set
    End Property
    <System.ComponentModel.Category("OSD")> _
    <System.ComponentModel.Description("Button Hilite Color")> _
    <System.ComponentModel.DisplayName("Button Hilite Color")> _
    Public Property ButtonHiliteColor() As System.Drawing.Color
        Get
            Return Me.Button3D2.HiLiteColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            Me.Button3D2.HiLiteColor = value
        End Set
    End Property

    Private Sub Button3D2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3D2.Click
        If Panel1.Top >= 0 Then
            Button3D2.Text = "Info"
            Panel1.Top = -65
        Else
            Button3D2.Text = "Hide"
            Panel1.Top = 0
        End If
        Panel1.Left = 0
        Refresh()
    End Sub

    Public Property DisplayImage() As System.Drawing.Image
        Get
            Return M_Pic
        End Get
        Set(ByVal value As System.Drawing.Image)
            M_Pic = New Bitmap(value)
            Dim CT As Integer = My.Computer.Clock.TickCount
            Dim C As Integer = CT - PT
            PT = CT
            If C > 0 Then
                AV = AV + (1000 / C)
                AC = AC + 1
                If AC = 10 Then
                    AC = 0
                    FPS = AV / 10
                    AV = 0
                End If
            End If
            If Me.DisplayImage IsNot Nothing Then
                Label4.Text = Me.DisplayImage.Width.ToString & " X " & Me.DisplayImage.Height.ToString
                Label5.Text = Me.DisplayImage.PixelFormat.ToString.Substring(6)
                Label6.Text = FPS.ToString("00") & " FPS"
            Else
                Label4.Text = "No Image"
                Label5.Text = ""
                Label6.Text = ""
            End If
        End Set
    End Property

    Private Sub ContainerPictureBox_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        If M_Pic IsNot Nothing Then
            e.Graphics.DrawImage(M_Pic, 0, 0)
        End If
    End Sub
End Class
